package com.learn.thread;

import cn.hutool.http.HttpUtil;

import java.io.File;
/**
 * 练习Thread .下载网络资源图像
 */
public class TestThread2 extends Thread{
    private String url;
    private String targetName;
    public TestThread2(String url, String targetName) {
        this.url = url;
        this.targetName = targetName;
    }
    @Override
    public void run() {
        WebLoaderResource1 webLoaderResource = new WebLoaderResource1();
        webLoaderResource.downloadImage(url,targetName);
        System.out.println("当前下载的文件名称为"+targetName);
    }

    public static void main(String[] args) {

        TestThread2 t1 = new TestThread2("https://oss.javaguide.cn/github/javaguide/books/image-20220424103035793.png", "t1.png");
        TestThread2 t2 = new TestThread2("https://oss.javaguide.cn/github/javaguide/books/image-20220424101217849.png", "t2.png");
        TestThread2 t3 = new TestThread2("https://oss.javaguide.cn/github/javaguide/books/image-20220424103124893.png", "t3.png");
        t1.start();
        t2.start();
        t3.start();
    }
}

/**
 * 练习Thread .下载网络资源图像
 */
class WebLoaderResource1 {
    public void downloadImage(String url,String targetName) {
        HttpUtil.downloadFile(url, new File(targetName));
    }
}